const initialState = {
    arr:[],
    copyarr:[]
}

export default (state = initialState, { type, payload,payload1 }) => {
   let newState = JSON.parse(JSON.stringify(state))
  switch (type) {
  case "getlist":
    newState.arr = payload
    newState.copyarr = payload
    return newState
  case "searchfn" :
   let newarr =  newState.copyarr.filter((item)=>{
      return item.status == payload
    })

   newState.arr = newarr
   return newState
  case "addFn":
    payload.key = Math.random()
    newState.arr.push(payload)
    return newState
  case "delfn" :
    newState.arr.splice(payload,1)
    return newState
  case "edifn":
    payload.key = Math.random()
    newState.arr.splice(payload1,1,payload)
    return newState
  default:
    return state
  }
}
